package com.l.web.util;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;

/**
 * Created by 严秋旺 on 2015/4/23.
 */
public class ControllerSupportBak  {

    public static final String ADD = "add";
    public static final String LIST = "list";
    public static final String UPDATE = "update";
    public static final String DETAIL = "detail";
    public static final String REMOVE = "remove";

    protected WebApplicationContext wac;

    protected String act = "";

    public void set_act(String act) {
        this.act = act;
    }

    public void setServletContext(ServletContext servletContext) {
        wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    }

    protected ServiceSupport getService(String serviceName) {
        return (ServiceSupport) wac.getBean(serviceName);
    }

    protected String simpleExecute(String name) {
        ServiceSupport service;
        String rsstr = "";
        switch (act) {
            case ADD:
                service = getService(name + "AddService");
                break;
            case UPDATE:
                service = getService(name + "UpdateService");
                break;
            case REMOVE:
                service = getService(name + "RemoveService");
                break;
            case DETAIL:
                service = getService(name + "DetailService");
                break;
            case LIST:
                service = getService(name + "ListService");
                break;
            default:
                service = getService(name + "Service");
        }
        //rsstr = service.execute();
        return rsstr;
    }

}
